package cn.maven.utils;

/**
 * 处理字符串
 */
public class StringUtil {


    public static String getString(String string) {
        //首字母大写后字符串
        String newStr = string.substring(0, 1).toUpperCase() + string.substring(1);
        //标记
        boolean flag = true;
        do {
            //获取下划线下标
            int _index = newStr.indexOf("_");
            if (_index > 0) {
                String _frontStr = newStr.substring(0, _index);
                String _rearStr = newStr.substring(_index + 1, _index + 2).toUpperCase() + newStr.substring(_index + 2);
                newStr = _frontStr + _rearStr;
            } else {
                flag = false;
            }
        } while (flag);
        return newStr;
    }

    public static String lowerStr(String string) {
        //首字母大写后字符串
        String newStr = string.substring(0, 1).toLowerCase() + string.substring(1);
        return newStr;
    }


    /**
     * 转换数据库列类型到java列类型
     *
     * @param columnType
     * @return
     */
    public static String swtichType(String columnType) {
        String javaType = null;
        switch (columnType) {
            case "VARCHAR":
                javaType = "String";
                break;
            case "BIGINT":
                javaType = "Long";
                break;
            case "tinyint":
                javaType = "Integer";
                break;
            case "INT":
                javaType = "Integer";
                break;
            case "DATETIME":
                javaType = "Date";
                break;
            case "DATE":
                javaType = "Date";
                break;
            case "DECIMAL":
                javaType = "BigDecimal";
                break;
            default:
                javaType = "String";
                break;
        }
        return javaType;
    }

    public static void main(String[] args) {
        System.out.println(getString("aaa_aaa_aaa"));
    }
}
